--Shaman Rotations
local is = "Wind Shear"
----------------------------------
-------- Enhance -----------------
----------------------------------

function CJ_EnhanceBuffs()
	local arg1,_,_,arg2 = GetWeaponEnchantInfo();
	
	if not arg1 then
		if CJ_Cast("Windfury Weapon") then return true end
	end
	
	if not arg2 then
		if CJ_Cast("Flametongue Weapon") then return true end
	end
	
	if not CJ_HB("Lightning Shield") then
		if CJ_Cast("Lightning Shield") then return true end;
	end
	
	return false;
end

function CJEnhShamRot()

	if cj_decurseself then
		if CJ_DecurseSelf() then return end
	end
	
	if cj_decurseparty then
		if CJ_DecurseAll() then return end
	end
	if CJ_OC() then StopAttack() return end
	if AmIFacing == false then return end
	CJ_Interrupt(is)
	
	if not cj_interruptmode and not UnitCastingInfo("target") and not UnitChannelInfo("target") then
		CJ_Cast("Wind Shear");
	end
	
	StartAttack()
	
	if UnitAffectingCombat("player") == 1 then
		if CJ_HP("player") < 50 then
			CJ_Cast("Shamanistic Rage");
		end
	end
	
	if not CJ_GCD() then return end;
	if CJ_EnhanceBuffs() then return end;
	
	if IsSpellInRange("Lava Lash") == 0 and IsSpellInRange("Earth Shock") == 1 then
		CJ_OffensiveDispel("Purge");
		if CJ_Cast("Unleash Elements") then return end;
		
		if cj_aoemode and not CJ_HD("Flame Shock") then
			if CJ_Cast("Flame Shock") then return end;
		elseif not cj_aoemode and CJ_HB("Unleash Flame") then
			if CJ_Cast("Flame Shock") then return end;
		end
		
		if cj_aoemode and CJ_HD("Flame Shock") then
			if CJ_Cast("Fire Nova") then return end;
		end
		
		if CJ_BS("Maelstrom Weapon") == 5 then
			if CJ_HP("player") < 30 then
				if CJ_Cast("Greater Healing Wave") then return end;
			end
			
			if cj_aoemode then
				if CJ_Cast("Chain Lightning") then return end;
			else
				if CJ_Cast("Lightning Bolt") then return end;
			end
		end
		if cj_frostshock then
			if CJ_Cast("Frost Shock") then return end
		end
		
		if CJ_Cast("Earth Shock") then return end;
		if CJ_Cast("Spiritwalker's Grace") then return end;
		if CJ_Cast("Lava Burst") then return end;
		if CJ_Cast("Lightning Bolt") then return end;
		return;
	elseif IsSpellInRange("Earth Shock") == 0 then return
	end
	
	if CJ_Totems() then return end;
	
	CJ_OffensiveDispel("Purge");
	
	if CJ_Cast("Lava Lash") then return end;

	if CJ_Cast("Stormstrike") then return end;
	
	if CJ_BS("Maelstrom Weapon") == 5 then
		if CJ_HP("player") < 30 then
			if CJ_Cast("Greater Healing Wave") then return end;
		end
		
		if cj_aoemode then
			if CJ_Cast("Chain Lightning") then return end;
		else
			if CJ_Cast("Lightning Bolt") then return end;
		end
	end
	
	if CJ_Cast("Unleash Elements") then return end;
	
	if cj_aoemode and CJ_HD("Flame Shock") then
		if CJ_Cast("Fire Nova") then return end;
	end
	
	if cj_aoemode and not CJ_HD("Flame Shock") then
		if CJ_Cast("Flame Shock") then return end;
	elseif not cj_aoemode and (CJ_HB("Unleash Flame") or not CJ_HD("Flame Shock")) then
		if CJ_Cast("Flame Shock") then return end;
	end
	
	if not CJ_HB("Unleash Flames") then
		if cj_frostshock then
			if CJ_Cast("Frost Shock") then return end
		end
		if CJ_Cast("Earth Shock") then return end;
	end
	
	if cj_cooldowns then
		RunMacroText("/use Ancient Petrified Seed");
		if CJ_Cast("Feral Spirit") then return end;
	end
	
	if CJ_Cast("Lava Lash") then return end;


end

------------------------------------------
-------------- Elemental -----------------
------------------------------------------
function CJ_EleBuffs()
	local arg1 = GetWeaponEnchantInfo();
	
	if not arg1 then
		if CJ_Cast("Flametongue Weapon") then return true end
	end
	
	if not CJ_HB("Lightning Shield") then
		if CJ_Cast("Lightning Shield") then return true end;
	end
	
	return false;
end

function CJEleShamRot()
	if cj_decurseself then
		if CJ_DecurseSelf() then return end
	end
	
	if cj_decurseparty then
		if CJ_DecurseAll() then return end
	end
	
	if CJ_OC() then StopAttack() return end
	if AmIFacing == false then return end
	CJ_Interrupt(is)
	
	if not cj_interruptmode and not UnitCastingInfo("target") and not UnitChannelInfo("target") then
		CJ_Cast("Wind Shear");
	end
	
	if cj_cooldowns and UnitAffectingCombat("player") == 1 then
		CJ_Cast("Elemental Mastery");
	end
	
	if not CJ_GCD() then return end
	if CJ_EleBuffs() then return end
	if CJ_Casting() then return end;
	if CJ_Totems() then return end;
	
	if UnitAffectingCombat("player") == 1 and CJ_MP("player") < 50 then
		if CJ_Cast("Thunderstorm") then return end;
	end		
	
	if IsSpellInRange("Lightning Bolt") == 0 then return end;
	
	CJ_OffensiveDispel("Purge");
	
	if CJ_Totems() then return end;
	
	if GetUnitSpeed("player") > 0 and not CJ_HB("Spiritwalker's Grace") then
		if CJ_Cast("Thunderstorm") then return end;
		if CJ_Cast("Unleash Elements") then return end;
		if CJ_Cast("Flame Shock") then return end;
		
		if cj_aoemode and CJ_HD("Flame Shock") then
			if CJ_Cast("Fire Nova") then return end;
		end
		
		if cj_aoemode and not CJ_HD("Flame Shock") then
			if CJ_Cast("Flame Shock") then return end
		elseif not cj_aoemode then
			if CJ_DTR("Flame Shock") <= 6.3 then
				if CJ_Cast("Flame Shock") then return end
			end
		end
		
		if cj_frostshock then
			if CJ_Cast("Frost Shock") then return end
		end
		
		if CJ_BS("Lightning Shield") >= 7 then
			if CJ_Cast("Earth Shock") then return end;
		end
		return 
	end
	
	if cj_aoemode and not CJ_HD("Flame Shock") then
		if CJ_Cast("Flame Shock") then return end
	elseif not cj_aoemode then
		if CJ_DTR("Flame Shock") <= 6.3 then
			if CJ_Cast("Flame Shock") then return end
		end
	end
	
	if CJ_DTR("Flame Shock") - (select(7,GetSpellInfo("Lava Burst"))/1000) >= .25 then
		if CJ_Cast("Lava Burst") then return end
	end
	
	if CJ_BS("Lightning Shield") == 9 then
		if CJ_Cast("Earth Shock") then return end
	end
	
	if cj_frostshock then
		if CJ_Cast("Frost Shock") then return end
	end
	
	if CJ_BS("Lightning Shield") > 6 and CJ_BTR("Flame Shock") > 7 then
		if CJ_Cast("Earth Shock") then return end
	end
	
	if cj_aoemode and CJ_HD("Flame Shock") then
		if CJ_Cast("Fire Nova") then return end;
	end
	
	if cj_aoemode then
		if CJ_Cast("Chain Lightning") then return end;
	end
	
	if CJ_Cast("Lightning Bolt") then return end;
end
------------------------------------------
-------------- Restoration----------------
------------------------------------------
function CJ_RestoBuffs()
	local arg1 = GetWeaponEnchantInfo();
	if not arg1 then
		print("Casting Earthliving Weapon")
		if CJ_Cast("Earthliving Weapon") then return true end
	end
	

	if TargetToES ~= nil then
		if CJ_HP(TargetToES) > 0 then
			if not CJ_THB(TargetToES,"Earth Shield") then
				if CJ_CastTarget("Earth Shield",TargetToES) then return true end;
			end
		end
	end
	if TargetToES == nil then
		if UnitExists("focus") == 1 then
			if CJ_HP("focus") > 0 then
				if not CJ_THB("focus","Earth Shield") then
					if CJ_CastTarget("Earth Shield","focus") then return true end;
					print("Refreshing Earth Shield")
				end
			end
		end
	end
	if RipT == true then
		if a == nil or m == nil or w == nil then
			a = 0
			m = 0
			w = 0
		end
		local npes = "raid"
		for i=1,25 do
			local tt = select(1,UnitName(npes..i))
			if tt~=nil then
				if (select(8,UnitBuff(tt,"Riptide"))~="player" or not CJ_THB(tt,"Riptide")) and UnitExists(tt)==1 and UnitInRange(tt)==true and UnitIsDeadOrGhost(tt)~=1 then a=UnitHealthMax(tt)-UnitHealth(tt)
					if a>m then m=a w=tt end
				end
			end
		end
		if w~=0 then
			if (select(8,UnitBuff(w,"Riptide"))~="player" or not CJ_THB(w,"Riptide")) and CJ_HP(w) < 97 and CJ_HP(w) > 0 then
				if CJ_CastTarget("Riptide",w) then return true end;
				if GetUnitSpeed('player')~=0 then
					CJ_Cast("Unleash Elements")
				end
				if CJ_HP(w) < 10 then
					CJ_Cast("Nature's Swiftness")
					if CJ_HB("Nature's Swiftness") then
						CJ_Cast("Greater Healing Wave")
					end
				end
				w = 0
				m = 0
				a = 0
			end
		end
	end
	if WShield ~= false then
		if not CJ_HB("Water Shield") then
			if CJ_Cast("Water Shield") then return true end;
			print("Casting Water Shield")
		end
	end
	return false;
end

local pct = 80
function CJRestoShamRot()
	if not CJ_GCD() then return end
	if CJ_Casting() then return end
	if CJ_DecurseSelf() then return end
	if CJ_DecurseAll() then return end
	if CJ_Totems() then return end
	if SpellIsTargeting() ~= 1 then
		CJ_Interrupt(is)
		if DpsMode == true then
			if not CJ_GCD() then return end
			if CJ_Casting() then return end
			if GetUnitSpeed("player") > 0 and not CJ_HB("Spiritwalker's Grace") then
				if CJ_Cast("Flame Shock") then return end;
				if CJ_RestoBuffs() then return end
				if CJ_DecurseSelf() then return end
				if CJ_DecurseAll() then return end
				if CJ_Totems() then return end			return 
			end
			if CJ_DTR("Flame Shock") <= 2.5 then
				if CJ_Cast("Flame Shock") then return end
			end
			if CJ_DTR("Flame Shock") - (select(7,GetSpellInfo("Lava Burst"))/1000) >= .25 then
				if CJ_Cast("Lava Burst") then return end
			end
			if CJ_Cast("Lightning Bolt") then return end;
		else
			if not CJ_GCD() then return end
			if CJ_Casting() then return end
			if CJ_RestoBuffs() then return end
			if CJ_DecurseSelf() then return end
			if CJ_DecurseAll() then return end
			if CJ_Totems() then return end
		end
	end
	local count = 0
	local grouptype = "raid"
	count = GetNumRaidMembers()
	if count == 0 then
		grouptype = "party"
		count = GetNumPartyMembers()
	end
	
	local numtoheal = 0;
	
end